package com.chujian.framework.echo.aop;

import com.chujian.framework.annotation.echo.UseEcho;
import com.chujian.framework.echo.EchoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.AfterReturningAdvice;

import java.lang.reflect.Method;

/**
 * 回显Advice
 *
 * @author yj
 * @since 2021-12-11
 */
@Slf4j
public class EchoMethodAdvice implements AfterReturningAdvice {

    private final EchoService echoService;

    public EchoMethodAdvice(EchoService echoService) {
        this.echoService = echoService;
    }

    @Override
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        echoService.echo(returnValue, method.getAnnotation(UseEcho.class));
    }
}
